/******************************************************************************
* This file is part of xn5106 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user licence from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   plc_hl_amr.c
* Desc:   PLC HL AMR C file
* Author: Jerry
* Date:   2011-5-19
* Note:   
* History:
*
******************************************************************************/
#include "os_api.h"
#include "plc.h"
#include "plc_if.h"
#include "plc_hl.h"
#include "plc_dl.h"
#include "plc_api.h"
#include "app.h"
#include "sys_log.h"
#include "mw_nram.h"
#include "xn5106x.h"
#include "plc_hl_amr.h"


#define PLC_HL_SND_TMOUT_X			3		// Send timeout paramter based one frame sending time
#define PLC_HL_BC_FRM_SEND_MAX		6										
#define PLC_HL_T_RSP_TMOUT			1000	// Terminal response time, 1S
// Unit: ms
#define PLC_HL_SND_TMOUT_VAL		((1000*(PLC_PH_BUFF_SIZE+7))/100)
#define PLC_HL_SND_FALSE_SYN_VAL    ((1000*128)/100)	

extern BOOL plc_hl_tmr_restart( PLC_HL_TMR_ID_T tmr_id, U32 tmout );
extern BOOL plc_hl_tmr_stop( PLC_HL_TMR_ID_T tmr_id );
extern BOOL plc_hl_tmr_rehook( PLC_HL_TMR_ID_T tmr_id, MSG_PLC_T msg_id, S8 *p_tmr_name );

extern PLC_HL_CTRL_T g_plc_hl_ctrl;
PLC_HL_AMR_CTRL_T g_plc_hl_amr_ctrl;

/*
* Function Name:
*   plc_hl_amr_init
* Description:
*   PLC HL AMR init
* Parameters:
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-23   
* Note:
*    
*/
BOOL plc_hl_amr_init( void )
{
	isOS_memset( &g_plc_hl_amr_ctrl, 0x00 ,sizeof(g_plc_hl_amr_ctrl) );
#ifdef MASTER_NODE
	#if PLC_AMR_WAIT_RSP_FLG
	g_plc_hl_amr_ctrl.m_wait_rsp_flg = FALSE;
	#endif

	#ifdef PLC_RESEND_FLG
	g_plc_hl_amr_ctrl.m_try_times = 0;
	g_plc_hl_amr_ctrl.m_p_snd_buff = NULL;
	#endif
#else
	
#endif
	return TRUE;
}

/*
* Function Name:
*   plc_hl_amr_busy_clr
* Description:
*   PLC HL AMR busy clear
* Parameters:
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-23   
* Note:
*    
*/
BOOL plc_hl_amr_busy_clr( void )
{
#if (defined(PLC_RESEND_FLG)&&defined(PLC_DL_ACK_FLG)&&defined(MASTER_NODE))
	if ( NULL != g_plc_hl_amr_ctrl.m_p_snd_buff )
	{
		if ( !sys_free( g_plc_hl_amr_ctrl.m_p_snd_buff ))
		{
			IS_ASSERT(0);
		}
		g_plc_hl_amr_ctrl.m_p_snd_buff = NULL;
	}
#endif

	return TRUE;
}

/*
* Function Name:
*   plc_hl_amr_app_send
* Description:
*   PLC HL app AMR proc
* Parameters:
*   U8* p_msg_data:
*   U16 len:
*   MSG_PLC_T msg_type:
*   BOOL* p_msg_rel_flg:
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-19   
* Note:
*    
*/
BOOL plc_hl_amr_app_send( U8 *p_msg_data, U16 len, MSG_PLC_T msg_type, BOOL *p_msg_rel_flg )
{
	BOOL status = FALSE;
	PLC_HL_SND_DATA_T *p_hl_snd_msg = (PLC_HL_SND_DATA_T*)p_msg_data;

	#ifdef VERIFY_SW_FLG
	{	// Verify sw with chip id
		typedef PACKED struct
		{
			U32 m_sn:28;
			U32 m_ft_me:4;
			U8 m_id;
			U8 m_me_id;
		}CHIP_SN_T;
		CHIP_SN_T *p_chip_sn = (CHIP_SN_T *)&rCHIP_SN;
		if (p_chip_sn->m_id != CHIP_ID)
		{
			return FALSE;
		}
	}
	#endif

	if ( MSG_AFN_TO_PLC_SEND ==  msg_type )
	{
	#if defined(MASTER_NODE)
		BOOL bc_flg = FALSE;
	#endif

	#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
		plc_hl_rsp_sig_set(FALSE);			// Clear response signal status
	#endif
	
	#if (defined(MASTER_NODE)&&(defined(PLC_VOID_COLLUDE)||defined(PLC_MAC_BIND)))
		if ( g_plc_hl_ctrl.m_state != PLC_HL_STATE_IDLE )
		{	// PLC HL is not in ready state
			PLC_HL_RSP_STATUS rsp_sta;
			if ( !sys_free( (U8*)p_hl_snd_msg ) )
			{
				IS_ASSERT(0);
				status = FALSE;
			}
		#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
			plc_hl_rsp_sig_set(FALSE);
			if ( plc_hl_rsp_sig_status(0) )
			{
				return FALSE;
			}
			if ( plc_hl_rsp_sig_status(30) )
			{
				return FALSE;
			}
			plc_hl_rsp_sig_set(TRUE);
			isOS_TmrSetExpireTick( &g_plc_hl_ctrl.m_sig_mon_tmr, (10000/10)+1 );
			isOS_TmrStart( &g_plc_hl_ctrl.m_sig_mon_tmr);
		#endif
			rsp_sta = PLC_HL_RSP_STA_AMR_SND_FAIL;
			if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_STAT, (U8*)&rsp_sta, 0 ) )
			{
				IS_ASSERT(0);
			}	
			*p_msg_rel_flg = TRUE;
			return TRUE;
		}
	
		#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
		isOS_TmrStop( &g_plc_hl_ctrl.m_sig_mon_tmr );
		#endif
	#endif
		
	#ifdef MASTER_NODE
		if ( 0 == isOS_memcmp( (U8*)p_hl_snd_msg->m_mac[PLC_MAC_SND_DES], c_plc_mac_broadcast, PLC_PH_MAC_LEN) )	
		{	// Broadcast frame
			bc_flg = TRUE;
			plc_if_bc_num_set( g_plc_hl_ctrl.m_bc_num+PLC_PARA_BC_NUM_INC );
		}
		else
		{
			plc_if_bc_num_set( g_plc_hl_ctrl.m_bc_num );
		}
	#endif
		
	#ifdef LOCAL_MAC_DYN
		plc_pl_mac_set( 0, (U8 *)p_hl_snd_msg->m_mac[PLC_MAC_SND_SRC], PLC_PH_MAC_LEN );
	#endif
	
	#ifdef MASTER_NODE
		{
			S32 try_times;
			try_times = (bc_flg)?PLC_HL_BC_FRM_SEND_MAX:1;
			status = TRUE;
			while( try_times-- )
			{
				status &= plc_dl_send( p_hl_snd_msg->m_mac[PLC_MAC_SND_DES], p_hl_snd_msg->m_mac[PLC_MAC_SND_SRC], \
								  PLC_DL_ID_NORMAL, p_hl_snd_msg->m_data, p_hl_snd_msg->m_data_len );
			#if 0
				if ( bc_flg )
				{
					status &= plc_dl_send( c_plc_mac_match_all, p_hl_snd_msg->m_mac[PLC_MAC_SND_SRC], \
								  PLC_DL_ID_NORMAL, p_hl_snd_msg->m_data, p_hl_snd_msg->m_data_len );
				}
			#endif
			}
		}
		#ifdef RSP_MAC_MATCH
		isOS_memcpy( g_plc_hl_amr_ctrl.m_rsp_mac, (U8*)p_hl_snd_msg->m_mac[PLC_MAC_SND_DES], PLC_PH_MAC_LEN );
		#endif
	#else
		#if (!defined(MASTER_NODE))&&(defined(PHASE_SEQ_24_FLG))
			plc_if_zcp_snd_flg_set( TRUE );
		#endif
		status = plc_dl_send( p_hl_snd_msg->m_mac[PLC_MAC_SND_DES], p_hl_snd_msg->m_mac[PLC_MAC_SND_SRC], \
							  PLC_DL_ID_NORMAL, p_hl_snd_msg->m_data, p_hl_snd_msg->m_data_len );
		#if (!defined(MASTER_NODE))&&(defined(PHASE_SEQ_24_FLG))
			plc_if_zcp_snd_flg_set( FALSE );
		#endif
	#endif
	#ifdef PLC_RESEND_FLG
		if ( status&& (!bc_flg) )
		{	// Send sucess and des MAC is not broadcast address
			U32 tmout;
		#if (defined(MASTER_NODE)&&(PLC_AMR_WAIT_RSP_FLG))
			g_plc_hl_amr_ctrl.m_wait_rsp_flg = TRUE;		// Need Response frame flag
		#endif
			tmout = (PLC_HL_SND_TMOUT_VAL*(plc_if_bc_num_get()+2))/(plc_if_params_get()->m_symbol_rate) \
						+PLC_HL_T_RSP_TMOUT+PLC_HL_SND_FALSE_SYN_VAL/(plc_if_params_get()->m_symbol_rate);
		#if (defined(PLC_DL_ACK_FLG))
			if( tmout )
			{	// DC node 
				if ( NULL != g_plc_hl_amr_ctrl.m_p_snd_buff )
				{
					if ( !sys_free( g_plc_hl_amr_ctrl.m_p_snd_buff ))
					{
						IS_ASSERT(0);
					}
					g_plc_hl_amr_ctrl.m_p_snd_buff = NULL;
				}
				g_plc_hl_amr_ctrl.m_snd_dl_id = PLC_DL_ID_NORMAL;
				g_plc_hl_amr_ctrl.m_p_snd_buff = (U8*)p_hl_snd_msg;
				g_plc_hl_amr_ctrl.m_try_times = 0;
				g_plc_hl_amr_ctrl.m_rsp_tmout = tmout;
				plc_hl_tmr_restart( PLC_HL_TMR_ID_RESEND, tmout );
			#ifdef LOG_FLG
				{		
					sys_utils_log( LOG_PLC_HL_TM_STA, &tmout, 2 );
				}
			#endif
			}
		#endif
		}
		else
		{	// Send failure in normal frame, or OK in broadcast frame
			PLC_HL_RSP_STATUS rsp_sta;
			if ( !sys_free( (U8*)p_hl_snd_msg ) )
			{
				IS_ASSERT(0);
				status = FALSE;
			}
		
			if ( bc_flg )
			{
				rsp_sta = (status)?PLC_HL_RSP_STA_BC_SND_OK:PLC_HL_RSP_STA_BC_SND_FAIL;
				if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_STAT, (U8*)&rsp_sta, 0 ) )
				{
					IS_ASSERT(0);
					status = FALSE;
				}
			}
			#ifdef PLC_SND_FAIL_STAT
			else
			{
				rsp_sta = (PLC_HL_RSP_STATUS)status;
				if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_STAT, (U8*)&rsp_sta, 0 ) )
				{
					IS_ASSERT(0);
					status = FALSE;
				}
			}
			#endif
		}
	#else
		// Slave node, should free directly. Slave node no timeout feature
		if ( !sys_free( (U8*)p_hl_snd_msg ) )
		{
			IS_ASSERT(0);
			status = FALSE;
		}
		if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_STAT, (U8*)&status, 0 ) )
		{
			IS_ASSERT(0);
		}
	#endif
		*p_msg_rel_flg = TRUE;
	}
	return TRUE;
}

/*
* Function Name:
*   plc_hl_amr_snd_tmout_proc
* Description:
*   PLC HL AMR Procedure (HL --> HL )
* Parameters:
*   U8 *p_msg_data: Message data pointer
*   U16 len: length of p_hl_msg
*   MSG_PLC_T msg_type: Message id
*   BOOL *p_msg_rel_flg: Message release flag
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-19   
* Note:
*    
*/
BOOL plc_hl_amr_snd_tmout_proc( U8 *p_msg_data, U16 len, MSG_PLC_T msg_type, BOOL *p_msg_rel_flg )
{
	BOOL status = TRUE;
#if (defined(MASTER_NODE)&&defined(PLC_FORCE_SEND))
	plc_pl_adc_ctrl( FALSE );				// Master is normal in stop mode 
#endif

#if (defined(PLC_RESEND_FLG)&&defined(PLC_DL_ACK_FLG))

	#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
	plc_hl_rsp_sig_set(FALSE);
	if ( plc_hl_rsp_sig_status( 0 ) )
	{	// If other phase has been reponsed, should stop time-out timer
		if ( !sys_free( g_plc_hl_amr_ctrl.m_p_snd_buff ))
		{
			IS_ASSERT(0);
		}
		g_plc_hl_amr_ctrl.m_p_snd_buff = NULL;
		return TRUE;
	}
	#endif

	g_plc_hl_amr_ctrl.m_try_times++;

	if ( g_plc_hl_amr_ctrl.m_try_times < PLC_HL_AMR_TRY_TIMES )
	{
		if ( g_plc_hl_amr_ctrl.m_p_snd_buff!=NULL )
		{
			PLC_HL_SND_DATA_T* p_hl_snd_msg;
			U32 tmout;
			U8 bc_num_old;
			p_hl_snd_msg = (PLC_HL_SND_DATA_T*)g_plc_hl_amr_ctrl.m_p_snd_buff;

			bc_num_old = plc_if_bc_num_get();
		#if (defined(PLC_RESEND_FLG)&&defined(PLC_BC_NUM_INC_FLG))
			plc_if_bc_num_set( plc_if_bc_num_get()+PLC_PARA_BC_NUM_INC );
		#endif
			// Resend: des MAC and src 
		#ifdef RESEND_DES_MAC
			status &= plc_dl_send( p_hl_snd_msg->m_mac[PLC_MAC_SND_DES], p_hl_snd_msg->m_mac[PLC_MAC_SND_SRC], \
								  (PLC_DL_ID)g_plc_hl_amr_ctrl.m_snd_dl_id, p_hl_snd_msg->m_data, \
								   p_hl_snd_msg->m_data_len );
		#else
			status &= plc_dl_send( c_plc_mac_match_all, c_plc_mac_match_all, \
								  (PLC_DL_ID)g_plc_hl_amr_ctrl.m_snd_dl_id, p_hl_snd_msg->m_data, \
								   p_hl_snd_msg->m_data_len );
		#endif
			tmout = (PLC_HL_SND_TMOUT_VAL*(plc_if_bc_num_get()+2))/(plc_if_params_get()->m_symbol_rate) \
					+PLC_HL_T_RSP_TMOUT+PLC_HL_SND_FALSE_SYN_VAL/(plc_if_params_get()->m_symbol_rate);
			plc_if_bc_num_set(bc_num_old);
			g_plc_hl_amr_ctrl.m_rsp_tmout = tmout;
			plc_hl_tmr_restart( PLC_HL_TMR_ID_RESEND, tmout );
		#ifdef LOG_FLG
			{		
				sys_utils_log( LOG_PLC_HL_TM_STA, &tmout, 2 );
			}
		#endif

		}
	}
	else
	{	// Try error
		status = FALSE;

	#if defined(MASTER_NODE)&&(PLC_AMR_WAIT_RSP_FLG)
		g_plc_hl_amr_ctrl.m_wait_rsp_flg = FALSE;
	#endif

	#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
		plc_hl_rsp_sig_set(FALSE);
		if ( plc_hl_rsp_sig_status(0) )
		{
			return FALSE;
		}
		if ( plc_hl_rsp_sig_status(30) )
		{
			return FALSE;
		}
		plc_hl_rsp_sig_set(TRUE);
		
		isOS_TmrSetExpireTick( &g_plc_hl_ctrl.m_sig_mon_tmr, (10000/10)+1 );
		isOS_TmrStart( &g_plc_hl_ctrl.m_sig_mon_tmr);
	#endif

	#ifdef PLC_DL_TMOUT_RSP_FLG
		// Send message to AFN App. Type(1B)+Len(1B)
		if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_TMOUT, (U8*)g_plc_hl_amr_ctrl.m_p_snd_buff, \
								   PLC_HL_SND_MSG_LEN(2) ) )
		{
			IS_ASSERT(0);
			if ( !sys_free( g_plc_hl_amr_ctrl.m_p_snd_buff ))
			{
				IS_ASSERT(0);
			}
		}
	#else
		if ( !sys_free( g_plc_hl_amr_ctrl.m_p_snd_buff ))
		{
			IS_ASSERT(0);
		}
	#endif
		
		g_plc_hl_amr_ctrl.m_p_snd_buff = NULL;
	}
#endif
	return status;
}

#ifdef MASTER_NODE
/*
* Function Name:
*   plc_hl_amr_tmout_get
* Description:
*   Get PLC AMR timeout 
* Parameters:
* Returns:
*   U32: unit: ms
* Author				Date 
*  Jerry				2013-2-21   
* Note:
*    
*/
U32 plc_hl_amr_tmout_get( void )
{
	U32 tmout;
	tmout = (PLC_HL_SND_TMOUT_VAL*(plc_if_bc_num_get()+2+PLC_PARA_BC_NUM_INC))/(plc_if_params_get()->m_symbol_rate) \
					+PLC_HL_T_RSP_TMOUT+PLC_HL_SND_FALSE_SYN_VAL/(plc_if_params_get()->m_symbol_rate);
	tmout = (tmout*PLC_HL_AMR_TRY_TIMES);
	return tmout;
}
#endif

/*
* Function Name:
*   plc_hl_amr_dl_rec
* Description:
*   PLC HL dl AMR receive ( from DL )
* Parameters:
*   U8 *p_msg_data: Message data pointer
*   U16 len: length of p_hl_msg
*   MSG_PLC_T msg_type: Message id
*   BOOL *p_msg_rel_flg: Message release flag
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-19   
* Note:
*    
*/
BOOL plc_hl_amr_dl_rec( U8 *p_msg_data, U16 len, MSG_PLC_T msg_type, BOOL *p_msg_rel_flg )
{
	BOOL status = TRUE;
	PLC_HL_SND_DATA_T *p_hl_msg;

	#ifdef VERIFY_SW_FLG
	{	// Verify sw with chip id
		typedef PACKED struct
		{
			U32 m_sn:28;
			U32 m_ft_me:4;
			U8 m_id;
			U8 m_me_id;
		}CHIP_SN_T;
		CHIP_SN_T *p_chip_sn = (CHIP_SN_T *)&rCHIP_SN;
		if (p_chip_sn->m_id != CHIP_ID)
		{
			return FALSE;
		}
	}
	#endif

	msg_type = msg_type;
	p_hl_msg = (PLC_HL_SND_DATA_T *)p_msg_data;

#if (defined(MASTER_NODE)&&defined(RSP_MAC_MATCH))	// Response MAC match
	if ( isOS_memcmp( g_plc_hl_amr_ctrl.m_rsp_mac, (U8*)p_hl_msg->m_mac[PLC_MAC_REC_SRC], PLC_PH_MAC_LEN ) \
		&&isOS_memcmp( g_plc_hl_amr_ctrl.m_rsp_mac, (U8*)c_plc_mac_match_all, PLC_PH_MAC_LEN ) )
//		&&isOS_memcmp( (U8*)c_plc_mac_match_all, (U8*)p_hl_msg->m_mac[PLC_MAC_REC_DES], PLC_PH_MAC_LEN ) )
	{
		return FALSE;
	}
#endif


#if (defined(MASTER_NODE)&&defined(PLC_FORCE_SEND))
	plc_pl_adc_ctrl( FALSE );				// Master is normal in stop mode 
#endif	

#if defined(MASTER_NODE)&&(PLC_AMR_WAIT_RSP_FLG)
	if ( !g_plc_hl_amr_ctrl.m_wait_rsp_flg )
	{	// This message will not be reported to App
		*p_msg_rel_flg = FALSE;
		break;	
	}
	g_plc_hl_amr_ctrl.m_wait_rsp_flg = FALSE;
#endif		
#if (defined(PLC_RESEND_FLG)&&defined(PLC_DL_ACK_FLG))
	if (TMR_STATE_RUNNING == g_plc_hl_ctrl.m_tmr.xTmrState)
	{	// Stop timer
		plc_hl_tmr_stop(PLC_HL_TMR_ID_RESEND);
		
		#ifdef LOG_FLG
		{		
			sys_utils_log( LOG_PLC_HL_TM_STP, NULL, 0 );
		}
		#endif
	}
#endif // end PLC_RESEND_FLG

#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
	plc_hl_rsp_sig_set(FALSE);
	if ( plc_hl_rsp_sig_status(0) )
	{
		return FALSE;
	}
	if ( plc_hl_rsp_sig_status(30) )
	{
		return FALSE;
	}
	plc_hl_rsp_sig_set(TRUE);
	isOS_TmrSetExpireTick( &g_plc_hl_ctrl.m_sig_mon_tmr, (10000/10)+1 );
	isOS_TmrStart( &g_plc_hl_ctrl.m_sig_mon_tmr);
#endif

	if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_DATA, \
							   (U8*)p_msg_data, PLC_HL_SND_MSG_LEN(p_hl_msg->m_data_len) ) )
	{
		sys_free( (U8*)p_msg_data );
		IS_ASSERT(0);
		status = FALSE;
	}		
	*p_msg_rel_flg = TRUE;	
	return status;
}

/*
* Function Name:
*   plc_hl_amr_dl_stat
* Description:
*   PLC HL dl AMR status ( from DL )
* Parameters:
*   U8 *p_msg_data: Message data pointer
*   U16 len: length of p_hl_msg
*   MSG_PLC_T msg_type: Message id
*   BOOL *p_msg_rel_flg: Message release flag
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-19   
* Note:
*    
*/
BOOL plc_hl_amr_dl_stat( U8 *p_msg_data, U16 len, MSG_PLC_T msg_type, BOOL *p_msg_rel_flg )
{
	PLC_DL_STAT_T *p_dl_stat;
	p_dl_stat = (PLC_DL_STAT_T*)p_msg_data;
	if (PLC_DL_STAT_FRAME_UPDATE ==*p_dl_stat )
	{	// DL Frame update information
	#if (defined(PLC_RESEND_FLG)&&defined(PLC_DL_ACK_FLG))
		//isOS_TmrStart( &g_plc_hl_ctrl.m_tmr );	// Restart send monitor timer 
		plc_hl_tmr_restart( PLC_HL_TMR_ID_RESEND, g_plc_hl_amr_ctrl.m_rsp_tmout );
	#endif
	}
	return TRUE;
}

/*
* Function Name:
*   plc_hl_amr_dl_err
* Description:
*   PLC HL dl error procedure
* Parameters:
*   U8 *p_msg_data: Message data pointer
*   U16 len: length of p_hl_msg
*   MSG_PLC_T msg_type: Message id
*   BOOL *p_msg_rel_flg: Message release flag
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2011-5-20   
* Note:
*    
*/
BOOL plc_hl_amr_dl_err( U8 *p_msg_data, U16 len, MSG_PLC_T msg_type, BOOL *p_msg_rel_flg )
{
	BOOL status = TRUE;
#if (defined(PLC_RESEND_FLG)&&defined(PLC_DL_ACK_FLG))
	if (TMR_STATE_RUNNING == g_plc_hl_ctrl.m_tmr.xTmrState)
	{	// Stop timer
		plc_hl_tmr_stop(PLC_HL_TMR_ID_RESEND);
		#ifdef LOG_FLG
		{		
			sys_utils_log( LOG_PLC_HL_TM_STP, NULL, 0 );
		}
		#endif
	}
#endif // end PLC_RESEND_FLG
	{
		PLC_HL_RSP_STATUS rsp_sta;
		rsp_sta = PLC_HL_RSP_STA_ERR;
		if ( FALSE == app_msg_snd( MSG_PLC_TO_APP_STAT, (U8*)&rsp_sta, 0 ) )
		{
			IS_ASSERT(0);
			status = FALSE;
		}
	}
	
	return status;
}


